) ≤2t (N/2) +n,t (1) =0 t (n) ≤2 (2T (N/4) +N/2) +n=4t (N/4) +2n T (n) ≤4 (2T (N/8) +N/4) +2n=8t (N/8) +3n ... T (n) ≤nt (1) + (log2n) xn= O (NLOGN)
In other words, in the optimal case, the time complexity of the fast sorting algorithm is O (NLOGN).
In the worst case, the sequence to be sorted is either positive or reverse, and each partition has only one sub-sequence that is less than the last one, noting
1. Time Complexity(1) Time Frequency the time required for executing an algorithm cannot be calculated theoretically. You must run the test on the computer before you can understand it. However, it is impossible and unnecessary for us to test each algorithm on the machine. We only need to know which algorithm takes mor
I. Complexity of TIMEThe concept time complexity is the one that is most affected by the change of n in the expression of the total number of operations (without coefficients) such as: General total number of operations the expression is similar to this: a*2N+B*N3+C*N2+D*N*LG (n) +e*n+FA! =0 o'clock, the complexity of
[Leetcode] Candy (min Candy), Time complexity O (n), Spatial complexity O (1), and only one-time traversal implementationOriginal question:There is N children standing in a line. Each child is assigned a rating value.You is giving candies to these children subjected to the following requirements:
Each child mu
First look at a few concepts. One is the complexity of time, and the other is the complexity of the asymptotic time. The former is the time consuming of an algorithm, which is the function of solving the problem size n, while the latter refers to the order of
"Pick" time complexity and space complexity 2007-09-16 13:43
1. Complexity of Time (1) Time frequencyThe time taken by an algorithm can not be calculated theoretically, it
, constants and other minor items in a function can often be ignored, and more attention should be paid to the order of the main item (the highest order). If you can compare the incremental growth of the key execution times function of several algorithms, it is essential to analyze: an algorithm that increases with n (input scale), it becomes more superior to another algorithm, or worse than another. This is the theoretical basis of the prior estimation method, and the
1. Complexity of TimeThe time complexity of the algorithm is the basic method to measure the efficiency of an algorithm. While reading other algorithmic tutorials, the time-complexity of the algorithm is somewhat jerky and difficult to understand. It is not possible to measu
Usually, for a given algorithm, we need to do two analyses. The first is to prove the correctness of the algorithm mathematically, this step mainly uses the formal proof method and the related inference mode, such as the cyclic invariant, the mathematical induction method and so on. On the basis of proving that the algorithm is correct, the second part is the time complexity of the analysis algorithm. The
The complexity of the algorithm is divided into time complexity and space complexity.Its role:Time complexity refers to the computational effort required to perform the algorithm;Spatial complexity refers to the amount of memory space required to execute the algorithm.(The
Usually, for a given algorithm, we need to do two analyses. The first is to prove the correctness of the algorithm mathematically, this step mainly uses the formal proof method and the related inference mode, such as the cyclic invariant, the mathematical induction method and so on. On the basis of proving that the algorithm is correct, the second part is the time complexity of the analysis algorithm. The
Time complexity and spatial complexity of the algorithm-summaryusually, for a given algorithm, we need to do two Analyses. The first is to prove the correctness of the algorithm mathematically, This step mainly uses the formal proof method and the related inference mode, such as the cyclic invariant, the mathematical induction method and so On. On the basis of pr
Original :11848739bo Master :ZolaladUsually, for a given algorithm, we need to do two analyses. The first is to prove the correctness of the algorithm mathematically , this step mainly uses the formal proof method and the related inference mode, such as the cyclic invariant, the mathematical induction method and so on. On the basis of proving that the algorithm is correct, the second part is the time complexity
Sorting method
Worst-time analysis
Average Time complexity
Degree of stability
Complexity of space
Bubble sort
O (N2)
O (N2)
Stability
O (1)
Quick Sort
O (N2)
O (N*LOG2N)
Not stable
O (log2n) ~o (n)
Select sort
O
ObjectiveIn the previous "Data structure and algorithm" I introduced the basic concept of data structure, also introduced the data structure can generally be divided into logical structure and physical structure. The logical structure is divided into set structure, linear structure, tree structure and graphic structure. The physical structure is divided into sequential storage structure and chained storage structure. The characteristics of these structures are also described. Then, the concept o
algorithm is expressed in F (N). S (n) =o (f (n)) where n is the size of the problem, S (n) represents spatial complexity.2. Complexity of Time(1) Time frequency an algorithm implementation of the time spent, from the theoretical can not be calculated, must be on the machin
time complexity analysis of an algorithm(1) Time frequencyThe time it takes for an algorithm to execute is theoretically impossible to figure out and must be tested on the machine. But we can not and do not need to test each algorithm, just know which algorithm spends more time
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.